import Vue from 'vue'
import Router from 'vue-router'
import home from '@/assets/imgs/home.png'
import preOrder from '@/assets/imgs/pre-order.png'
import advance from '@/assets/imgs/advance-production-plan.png'
import productionPlan from '@/assets/imgs/productionPlan.png'
import OutsourcingManagement from '@/assets/imgs/OutsourcingManagement.png'
import MonthlyPlan from '@/assets/imgs/MonthlyPlan.png'
import MonthlyPlanningAndScheduling from '@/assets/imgs/MonthlyPlanning-and-Scheduling.png'
import BasicData from '@/assets/imgs/BasicData.png'
import erp from '@/assets/imgs/erp.png'
import setting from '@/assets/imgs/setting.png'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '工作台', icon: home, affix: true }
      }
    ]
  },
  {
    path: '/pre',
    component: Layout,
    redirect: '/pre/headquartersLevel',
    name: 'pre',
    meta: { title: '预排订单管理', icon: preOrder },
    children: [
      {
        path: 'headquartersLevel',
        name: 'headquartersLevel',
        meta: { title: '预排订单总部层级' },
        component: () => import('@/views/pre-order/index')
      },
      {
        path: 'headquartersDetails',
        name: 'headquartersDetails',
        component: () => import('@/views/pre-order/details'),
        hidden: true,
        meta: {
          title: '预排订单管理详情',
          noCache: true,
          activeMenu: '/pre/headquartersLevel'
          //   affix: true,
        }
      },
      {
        path: 'regionalLevel',
        name: 'regionalLevel',
        meta: { title: '预排订单地区层级' },
        component: () => import('@/views/pre-order/regionalLevel.vue')
      },
      {
        path: 'regionalDetails',
        name: 'regionalDetails',
        component: () => import('@/views/pre-order/details'),
        hidden: true,
        meta: {
          title: '预排订单管理详情',
          noCache: true,
          activeMenu: '/pre/regionalLevel'
          //   affix: true,
        }
      },
      {
        path: 'factoryLevel',
        name: 'factoryLevel',
        meta: { title: '预排订单工厂层级' },
        component: () => import('@/views/pre-order/factoryLevel.vue')
      },
      {
        path: 'factoryDetails',
        name: 'factoryDetails',
        component: () => import('@/views/pre-order/details'),
        hidden: true,
        meta: {
          title: '预排订单管理详情',
          noCache: true,
          activeMenu: '/pre/factoryLevel'
          //   affix: true,
        }
      }
    ]
  },
  {
    path: '/advance',
    component: Layout,
    redirect: 'firstLevelScheduling',
    name: 'advance',
    meta: { title: '预排生产计划', icon: advance },
    children: [
      {
        path: 'firstLevelScheduling',
        name: 'firstLevelScheduling',
        meta: { title: '一级排产' },
        component: () => import('@/views/advance-production-plan/index.vue')
      },
      {
        path: 'secondaryScheduling',
        name: 'secondaryScheduling',
        meta: { title: '二级排产' },
        component: () =>
          import('@/views/advance-production-plan/secondaryScheduling.vue')
      },
      {
        path: 'threeLevelScheduling',
        name: 'threeLevelScheduling',
        meta: { title: '三级排产' },
        component: () =>
          import('@/views/advance-production-plan/threeLevelScheduling.vue')
      },
      {
        path: 'workingCalendar',
        name: 'workingCalendar',
        component: () =>
          import('@/views/advance-production-plan/workingCalendar.vue'),
        hidden: true,
        meta: {
          title: '工作日历设置',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/erp',
    component: Layout,
    redirect: '',
    name: 'erp',
    meta: { title: 'ERP实际订单管理', icon: erp },
    children: [
      {
        path: 'erpHeadquartersLevel',
        name: 'erpHeadquartersLevel',
        meta: { title: 'ERP订单总部层级' },
        component: () => import('@/views/erp/erpHeadquartersLevel.vue')
      },
      {
        path: 'erpRegionalLevel',
        name: 'erpRegionalLevel',
        meta: { title: 'ERP订单地区层级' },
        component: () => import('@/views/erp/erpRegionalLevel.vue')
      },
      {
        path: 'erpFactoryLevel',
        name: 'erpFactoryLevel',
        meta: { title: 'ERP订单工厂层级' },
        component: () => import('@/views/erp/erpFactoryLevel.vue')
      },
      {
        path: 'erpHeadquartersDetails',
        name: 'erpHeadquartersDetails',
        component: () => import('@/views/erp/erpHeadquartersDetails.vue'),
        hidden: true,
        meta: {
          title: '订单详情',
          noCache: true,
          activeMenu: '/erp/erpHeadquartersLevel'
          //   affix: true,
        }
      },
      {
        path: 'erpRegionalDetails',
        name: 'erpRegionalDetails',
        component: () => import('@/views/erp/erpDetails.vue'),
        hidden: true,
        meta: {
          title: '订单详情',
          noCache: true,
          activeMenu: '/erp/erpRegionalLevel'
          //   affix: true,
        }
      },
      {
        path: 'erpFactoryDetails',
        name: 'erpFactoryDetails',
        component: () => import('@/views/erp/erpDetails.vue'),
        hidden: true,
        meta: {
          title: '订单详情',
          noCache: true,
          activeMenu: '/erp/erpFactoryLevel'
          //   affix: true,
        }
      }
    ]
  },
  {
    path: '/erpAdvance',
    name: 'erpAdvance',
    component: Layout,
    meta: { title: '生产计划', icon: productionPlan },
    children: [
      {
        path: 'erpFirstLevelScheduling',
        name: 'erpFirstLevelScheduling',
        meta: { title: '一级排产' },
        component: () => import('@/views/erp-advance/index.vue')
      },
      {
        path: 'erpSecondaryScheduling',
        name: 'erpSecondaryScheduling',
        meta: { title: '二级排产' },
        component: () => import('@/views/erp-advance/secondaryScheduling.vue')
      },
      {
        path: 'erpThreeLevelScheduling',
        name: 'erpThreeLevelScheduling',
        meta: { title: '三级排产' },
        component: () => import('@/views/erp-advance/threeLevelScheduling.vue')
      },
      {
        path: 'erpFirstworkingCalendar/:type',
        name: 'workingCalendar',
        component: () => import('@/views/erp-advance/workingCalendar.vue'),
        hidden: true,
        meta: {
          title: '工作日历设置',
          noCache: true,
          activeMenu: '/erpAdvance/erpFirstLevelScheduling'
        }
      },
      {
        path: 'erpSecondworkingCalendar/:type',
        name: 'workingCalendar',
        component: () => import('@/views/erp-advance/workingCalendar.vue'),
        hidden: true,
        meta: {
          title: '工作日历设置',
          noCache: true,
          activeMenu: '/erpAdvance/erpSecondaryScheduling'
        }
      },
      {
        path: 'erpThreeworkingCalendar/:type',
        name: 'workingCalendar',
        component: () => import('@/views/erp-advance/workingCalendar.vue'),
        hidden: true,
        meta: {
          title: '工作日历设置',
          noCache: true,
          activeMenu: '/erpAdvance/erpThreeLevelScheduling'
        }
      }
    ]
  },
  {
    path: '/outsourcing',
    name: 'outsourcing',
    component: Layout,
    meta: { title: '外协管理', icon: OutsourcingManagement },
    redirect: '/outsourcing/management',
    children: [
      {
        path: 'management',
        name: 'management',
        meta: { title: '外协管理' },
        component: () => import('@/views/outsourcingManagement/index.vue')
      }
    ]
  },
  //   月计划
  {
    path: '/month',
    name: 'month',
    component: Layout,
    meta: { title: '月计划', icon: MonthlyPlan },
    children: [
      {
        path: 'order',
        name: 'order',
        meta: { title: '月计划订单管理' },
        component: () => import('@/views/monthlyPlan/order.vue')
      },
      {
        path: 'edit',
        name: 'monthlyPlanEdit',
        meta: {
          title: '编辑订单',
          activeMenu: '/monthlyPlan/order'
        },
        hidden: true,
        component: () => import('@/views/monthlyPlan/edit.vue')
      },
      {
        path: 'details',
        name: 'monthlyPlanDetails',
        meta: {
          title: '订单详情',
          activeMenu: '/monthlyPlan/order'
        },
        hidden: true,
        component: () => import('@/views/monthlyPlan/details.vue')
      },
      {
        path: 'planed',
        name: 'planed',
        meta: { title: '月计划排产' },
        component: () => import('@/views/monthlyPlaned/planed.vue')
      },
      {
        path: 'factoryCalendar',
        name: 'factoryCalendar',
        component: () => import('@/views/monthlyPlaned/workingCalendar.vue'),
        hidden: true,
        meta: {
          title: '工厂日历设置',
          noCache: true
        }
      },
      {
        path: 'reverseOrder',
        name: 'reverseOrder',
        component: () => import('@/views/monthlyPlaned/reverseOrder.vue'),
        hidden: true,
        meta: {
          title: '倒序排产',
          noCache: true
        }
      }
    ]
  },
  //   {
  //     path: "/monthlyPlan",
  //     name: "monthlyPlan",
  //     component: Layout,
  //     meta: { title: "月计划订单管理", icon: MonthlyPlan },
  //     redirect: "/monthlyPlan/order",
  //     children: [
  //       {
  //         path: "order",
  //         name: "order",
  //         meta: { title: "月计划订单管理" },
  //         component: () => import("@/views/monthlyPlan/order.vue"),
  //       },
  //       {
  //         path: "edit",
  //         name: "monthlyPlanEdit",
  //         meta: {
  //           title: "编辑订单",
  //           activeMenu: "/monthlyPlan/order",
  //         },
  //         hidden: true,
  //         component: () => import("@/views/monthlyPlan/edit.vue"),
  //       },
  //       {
  //         path: "details",
  //         name: "monthlyPlanDetails",
  //         meta: {
  //           title: "订单详情",
  //           activeMenu: "/monthlyPlan/order",
  //         },
  //         hidden: true,
  //         component: () => import("@/views/monthlyPlan/details.vue"),
  //       },
  //     ],
  //   },
  //   {
  //     path: "/monthlyPlaned",
  //     name: "monthlyPlaned",
  //     component: Layout,
  //     meta: { title: "月计划排产", icon: MonthlyPlanningAndScheduling },
  //     redirect: "/monthlyPlaned/planed",
  //     children: [
  //       {
  //         path: "planed",
  //         name: "planed",
  //         meta: { title: "月计划排产" },
  //         component: () => import("@/views/monthlyPlaned/planed.vue"),
  //       },
  //       {
  //         path: "factoryCalendar",
  //         name: "factoryCalendar",
  //         component: () => import("@/views/monthlyPlaned/workingCalendar.vue"),
  //         hidden: true,
  //         meta: {
  //           title: "工厂日历设置",
  //           noCache: true,
  //         },
  //       },
  //       {
  //         path: "reverseOrder",
  //         name: "reverseOrder",
  //         component: () => import("@/views/monthlyPlaned/reverseOrder.vue"),
  //         hidden: true,
  //         meta: {
  //           title: "倒序排产",
  //           noCache: true,
  //         },
  //       },
  //     ],
  //   },
  //  周计划
  {
    path: '/weeklyPlan',
    name: 'weeklyPlan',
    component: Layout,
    meta: { title: '周计划' },
    children: [
      {
        path: 'directorOrder',
        name: 'weeklyPlanDirectorOrder',
        meta: { title: '计划厂长级订单管理' },
        component: () => import('@/views/weeklyPlanDirector/order/index.vue')
      },
      {
        path: 'directorPlaned',
        name: 'weeklyPlanDirectorPlaned',
        meta: {
          title: '计划厂长级排产'
        },
        component: () =>
          import('@/views/weeklyPlanWorkshopDirector/order/planed.vue')
      },
      {
        path: 'workshopOrder',
        name: 'workshopOrder',
        meta: { title: '车间主任级订单管理 ' },
        component: () =>
          import('@/views/weeklyPlanWorkshopDirector/order/index.vue')
      },
      {
        path: 'worlshopPlaned',
        name: 'workshopPlaned',
        meta: {
          title: '车间主任级排产'
        },
        component: () =>
          import('@/views/weeklyPlanWorkshopDirector/order/planed.vue')
      },
      {
        path: 'details',
        name: 'weeklyPlanWorkshopDirectorDetails',
        hidden: true,
        meta: { title: '订单详情', activeMenu: '/weeklyPlan' },
        component: () =>
          import('@/views/weeklyPlanWorkshopDirector/order/details.vue')
      },
      {
        path: 'edit',
        name: 'weeklyPlanWorkshopDirectorEdit',
        hidden: true,
        meta: { title: '订单编辑', activeMenu: '/weeklyPlan' },
        component: () =>
          import('@/views/weeklyPlanWorkshopDirector/order/edit.vue')
      },

      {
        path: 'factoryCalendar',
        name: 'weeklyPlanWorkshopDirectorFactoryCalendar',
        component: () =>
          import(
            '@/views/weeklyPlanWorkshopDirector/order/workingCalendar.vue'
          ),
        hidden: true,
        meta: {
          title: '工厂日历设置',
          activeMenu: '/weeklyPlan',
          noCache: true
        }
      },
      {
        path: 'situation',
        name: 'situation',
        meta: {
          title: '物料齐套情况'
        },
        // hidden: true,
        component: () =>
          import('@/views/weeklyPlanWorkshopDirector/order/situation.vue')
      }
    ]
  },
  //   日计划
  {
    path: '/dayplan',
    name: 'dayplan',
    component: Layout,
    meta: { title: '日计划' },
    children: [
      {
        path: 'order',
        name: 'order',
        meta: { title: '日计划订单管理' },
        component: () => import('@/views/dayplan/order.vue')
      },
      {
        path: 'edit',
        name: 'monthlyPlanEdit',
        meta: {
          title: '编辑订单',
          activeMenu: '/dayplan/order'
        },
        hidden: true,
        component: () => import('@/views/dayplan/edit.vue')
      },
      {
        path: 'details',
        name: 'monthlyPlanDetails',
        meta: {
          title: '订单详情',
          activeMenu: '/dayplan/order'
        },
        hidden: true,
        component: () => import('@/views/dayplan/details.vue')
      },
      {
        path: 'planed',
        name: 'planed',
        meta: { title: '日计划排产' },
        component: () => import('@/views/monthlyPlaned/planed.vue')
      },
      {
        path: 'factoryCalendar',
        name: 'factoryCalendar',
        component: () => import('@/views/monthlyPlaned/workingCalendar.vue'),
        hidden: true,
        meta: {
          title: '工厂日历设置',
          noCache: true
        }
      },
      {
        path: 'reverseOrder',
        name: 'reverseOrder',
        component: () => import('@/views/monthlyPlaned/reverseOrder.vue'),
        hidden: true,
        meta: {
          title: '倒序排产',
          noCache: true
        }
      },
      {
        path: 'materials',
        name: 'materials',
        component: () => import('@/views/dayplan/materials.vue'),
        meta: {
          title: '物料齐套情况'
        }
      }
    ]
  },
  //   基础数据
  //   {
  //     path: "/basicData",
  //     name: "basicData",
  //     meta: { title: "基础数据", icon: BasicData },
  //     component: Layout,
  //     redirect: "/basicData/customerManagement",
  //     children: [

  //     ],
  //   },
  //   系统管理
  {
    path: '/systemManagement',
    name: 'systemManagement',
    meta: { title: '系统管理', icon: setting },
    component: Layout,
    children: [
      {
        path: 'resource',
        name: 'resource',
        meta: { title: '资源库' },
        component: () => import('@/views/system/resource/index.vue')
      },
      {
        path: 'customerManagement',
        name: 'customerManagement',
        meta: { title: '客户管理' },
        component: () => import('@/views/basicData/customerManagement.vue')
      },
      {
        path: 'productData',
        name: 'productData',
        meta: { title: '标准产品配置' },
        component: () => import('@/views/basicData/productData.vue')
      },
      {
        path: 'role',
        name: 'role',
        meta: { title: '角色与权限' },
        component: () => import('@/views/system/roles/index.vue')
      },
      {
        path: 'addRole',
        name: 'addRole',
        hidden: true,
        meta: { title: '角色与权限', activeMenu: '/systemManagement/role' },
        component: () => import('@/views/system/roles/add.vue')
      },
      {
        path: 'organizationalStructure',
        name: 'organizationalStructure',
        meta: { title: '组织架构' },
        component: () =>
          import('@/views/system/organizationalStructure/index.vue')
      },
      {
        path: 'editEmployee',
        name: 'editEmployee',
        hidden: true,
        meta: {
          title: '编辑员工信息',
          activeMenu: '/systemManagement/organizationalStructure'
        },
        component: () =>
          import('@/views/system/organizationalStructure/editEmployee.vue')
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  /* {
    path: "/permission",
    component: Layout,
    redirect: "/permission/page",
    alwaysShow: true, // will always show the root menu
    name: "Permission",
    meta: {
      title: "permission",
      icon: "lock",
      roles: ["admin", "editor"], // you can set roles in root nav
    },
    children: [
      {
        path: "page",
        component: () => import("@/views/permission/page"),
        name: "PagePermission",
        meta: {
          title: "pagePermission",
          roles: ["admin"], // or you can only set roles in sub nav
        },
      },
      {
        path: "directive",
        component: () => import("@/views/permission/directive"),
        name: "DirectivePermission",
        meta: {
          title: "directivePermission",
          // if do not set roles, means: this page does not require permission
        },
      },
      {
        path: "role",
        component: () => import("@/views/permission/role"),
        name: "RolePermission",
        meta: {
          title: "rolePermission",
          roles: ["admin"],
        },
      },
    ],
  },

  {
    path: "/icon",
    component: Layout,
    children: [
      {
        path: "index",
        component: () => import("@/views/icons/index"),
        name: "Icons",
        meta: { title: "icons", icon: "icon", noCache: true },
      },
    ],
  }, */

  /** when your routing map is too long, you can split it into small modules **/
  //   componentsRouter,
  //   chartsRouter,
  //   nestedRouter,
  //   tableRouter,

  /*  {
    path: "/example",
    component: Layout,
    redirect: "/example/list",
    name: "Example",
    meta: {
      title: "example",
      icon: "el-icon-s-help",
    },
    children: [
      {
        path: "create",
        component: () => import("@/views/example/create"),
        name: "CreateArticle",
        meta: { title: "createArticle", icon: "edit" },
      },
      {
        path: "edit/:id(\\d+)",
        component: () => import("@/views/example/edit"),
        name: "EditArticle",
        meta: {
          title: "editArticle",
          noCache: true,
          activeMenu: "/example/list",
        },
        hidden: true,
      },
      {
        path: "list",
        component: () => import("@/views/example/list"),
        name: "ArticleList",
        meta: { title: "articleList", icon: "list" },
      },
    ],
  },

  {
    path: "/tab",
    component: Layout,
    children: [
      {
        path: "index",
        component: () => import("@/views/tab/index"),
        name: "Tab",
        meta: { title: "tab", icon: "tab" },
      },
    ],
  },

  {
    path: "/error",
    component: Layout,
    redirect: "noRedirect",
    name: "ErrorPages",
    meta: {
      title: "errorPages",
      icon: "404",
    },
    children: [
      {
        path: "401",
        component: () => import("@/views/error-page/401"),
        name: "Page401",
        meta: { title: "page401", noCache: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404"),
        name: "Page404",
        meta: { title: "page404", noCache: true },
      },
    ],
  },

  {
    path: "/error-log",
    component: Layout,
    children: [
      {
        path: "log",
        component: () => import("@/views/error-log/index"),
        name: "ErrorLog",
        meta: { title: "errorLog", icon: "bug" },
      },
    ],
  },

  {
    path: "/excel",
    component: Layout,
    redirect: "/excel/export-excel",
    name: "Excel",
    meta: {
      title: "excel",
      icon: "excel",
    },
    children: [
      {
        path: "export-excel",
        component: () => import("@/views/excel/export-excel"),
        name: "ExportExcel",
        meta: { title: "exportExcel" },
      },
      {
        path: "export-selected-excel",
        component: () => import("@/views/excel/select-excel"),
        name: "SelectExcel",
        meta: { title: "selectExcel" },
      },
      {
        path: "export-merge-header",
        component: () => import("@/views/excel/merge-header"),
        name: "MergeHeader",
        meta: { title: "mergeHeader" },
      },
      {
        path: "upload-excel",
        component: () => import("@/views/excel/upload-excel"),
        name: "UploadExcel",
        meta: { title: "uploadExcel" },
      },
    ],
  },

  {
    path: "/zip",
    component: Layout,
    redirect: "/zip/download",
    alwaysShow: true,
    name: "Zip",
    meta: { title: "zip", icon: "zip" },
    children: [
      {
        path: "download",
        component: () => import("@/views/zip/index"),
        name: "ExportZip",
        meta: { title: "exportZip" },
      },
    ],
  },

  {
    path: "/pdf",
    component: Layout,
    redirect: "/pdf/index",
    children: [
      {
        path: "index",
        component: () => import("@/views/pdf/index"),
        name: "PDF",
        meta: { title: "pdf", icon: "pdf" },
      },
    ],
  },
  {
    path: "/pdf/download",
    component: () => import("@/views/pdf/download"),
    hidden: true,
  },

  {
    path: "/theme",
    component: Layout,
    children: [
      {
        path: "index",
        component: () => import("@/views/theme/index"),
        name: "Theme",
        meta: { title: "theme", icon: "theme" },
      },
    ],
  },

  {
    path: "/clipboard",
    component: Layout,
    children: [
      {
        path: "index",
        component: () => import("@/views/clipboard/index"),
        name: "ClipboardDemo",
        meta: { title: "clipboardDemo", icon: "clipboard" },
      },
    ],
  },

  {
    path: "/i18n",
    component: Layout,
    children: [
      {
        path: "index",
        component: () => import("@/views/i18n-demo/index"),
        name: "I18n",
        meta: { title: "i18n", icon: "international" },
      },
    ],
  },

  {
    path: "external-link",
    component: Layout,
    children: [
      {
        path: "https://github.com/PanJiaChen/vue-element-admin",
        meta: { title: "externalLink", icon: "link" },
      },
    ],
  }, */

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
